package com.rfid.emergencywarehouse.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.rfid.base.base.BaseAdapter;
import com.rfid.emergencywarehouse.R;
import com.rfid.emergencywarehouse.entity.KW;
import com.rfid.emergencywarehouse.entity.KWAsset;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class KwAdapter extends BaseAdapter<KwAdapter.MyHolder, KW> {


    public KwAdapter(List<KW> data) {
        super(data);
    }

    @Override
    protected int getLayout() {
        return R.layout.item_kw;
    }

    @Override
    protected MyHolder getViewHolder(View view) {
        return new MyHolder(view);
    }

    @Override
    protected void bindView(MyHolder holder, int position, KW t) {
        KW kw = mData.get(position);
        holder.kw_list.removeAllViews();
        holder.kw.setText("库位：" + kw.getKw());
        for (KWAsset asset : kw.getAssets()) {
            View view = LayoutInflater.from(holder.kw.getContext()).inflate(R.layout.kw_item,null);
            TextView wl = view.findViewById(R.id.wl);
            TextView sku = view.findViewById(R.id.sku);
            TextView num = view.findViewById(R.id.num);
            wl.setText("物料：" + asset.getMaterialName());
            sku.setText("型号：" + asset.getSkuModel());
            num.setText("数量：" + asset.getRealCount() + "/" + asset.getPlanCount());
            holder.kw_list.addView(view);
        }
    }

    class MyHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.kw)
        TextView kw;
        @BindView(R.id.kw_list)
        LinearLayoutCompat kw_list;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
